package com.cuit.riskassessment.action.ru;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.cuit.riskassessment.service.RuService;
import com.cuit.riskassessment.util.Result;
import com.cuit.riskassessment.vo.RuParam;

/**
 * ru中的相关请求
 * @author Yang_Zhiqin-pc
 *
 */
@Controller
@RequestMapping(value="ru")
public class RuAction {
	@Autowired
	@Resource(name="ruService")
	private RuService ruService;
	/**
	 * ru电力请求
	 * @param res
	 * @param ru
	 * @return
	 */
	@RequestMapping(value="addorupdate1")
	public @ResponseBody Object addOrUpdate1(HttpServletResponse res, RuParam ru)
	{
		
		res.setHeader("Accept",  "application/json");
		Result result = new Result();
		result.setMessage("添加成功！");
		result.setSuccess(true);
		if(ru.getL()==null)ru.setL(1000.0);
		if(!this.ruService.addOrUpdateRu1(ru))
		{
			result.setSuccess(false);
			result.setMessage("添加失败！");
		}
		return result;
	}
	/**
	 * ru 通信请求
	 * @param res
	 * @param ru
	 * @return
	 */
	@RequestMapping(value="addorupdate2")
	public @ResponseBody Object addOrUpdate2(HttpServletResponse res, RuParam ru)
	{
		
		res.setHeader("Accept",  "application/json");
		Result result = new Result();
		result.setMessage("添加成功！");
		result.setSuccess(true);
		if(ru.getL()==null)ru.setL(1000.0);
		if(!this.ruService.addOrUpdateRu2(ru))
		{
			result.setSuccess(false);
			result.setMessage("添加失败！");
		}
		return result;
	}
	/**
	 * ru 电力
	 * @param res
	 * @param projid
	 * @return
	 */
	@RequestMapping(value="get1")
	public @ResponseBody Object getRu1(HttpServletResponse res, @RequestParam(value="projid")int projid)
	{
		res.setHeader("Accept",  "application/json");
		Result result = new Result();
		RuParam obj = this.ruService.getRu1(projid);
		if(obj.getRuResult()==null&&obj.getNda()==null)
		{
			result.setSuccess(false);
		}else
		{
			result.setSuccess(true);
			result.setOthers(obj);
		}
		
		return result;
	}
	
	/**
	 * ru 电力
	 * @param res
	 * @param projid
	 * @return
	 */
	@RequestMapping(value="get2")
	public @ResponseBody Object getRu2(HttpServletResponse res, @RequestParam(value="projid")int projid)
	{
		res.setHeader("Accept",  "application/json");
		Result result = new Result();
		RuParam obj = this.ruService.getRu2(projid);
		if(obj.getRuResult()==null&&obj.getNda()==null)
		{
			result.setSuccess(false);
		}else
		{
			result.setSuccess(true);
			result.setOthers(obj);
		}
		
		return result;
	}
	
}
